Skip to content

Fix WSA protocol info cleanup in request shutdown#20942

Open
EdmondDantes wants to merge 1 commit intophp:PHP-8.5from
true-async:PHP-8.5.0-wsa-fix
Open

Fix WSA protocol info cleanup in request shutdown#20942
EdmondDantes wants to merge 1 commit intophp:PHP-8.5from
true-async:PHP-8.5.0-wsa-fix

Conversation

@EdmondDantes
Copy link
Copy Markdown

@EdmondDantes EdmondDantes commented Jan 15, 2026

PHP_FUNCTION(socket_wsaprotocol_info_export)
{
 .....
        // allocate Request memory here
	seg_name = zend_strpprintf(0, "php_wsa_for_%u", SOCKETS_G(wsa_child_count)++);
	map = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(WSAPROTOCOL_INFO), ZSTR_VAL(seg_name));
	if (NULL != map) {

        // put to persistent memory array
        zend_hash_add_ptr(&(SOCKETS_G(wsa_info)), seg_name, map);

Memory allocated for the request is destroyed before the SOCKETS_G(wsa_info) array is destructed

If the socket_wsaprotocol_info_release method is not called, the application terminates with the message "zend_mm_heap corrupted"

The code proposed in this patch is not ideal, and it may be worth removing the creation of the array in persistent memory. I do not fully understand the reason why it was done this way. Nevertheless, this code works correctly.

P.S. Apparently, this bug is present in all PHP versions.

@devnexen
Copy link
Copy Markdown
Member

Hi please target PHP-8.5 (without the last .0) thanks :)

@EdmondDantes EdmondDantes changed the base branch from PHP-8.5.0 to PHP-8.5 January 15, 2026 12:35
Add zend_hash_clean for wsa_info hashtable in PHP_RSHUTDOWN_FUNCTION
to properly cleanup WSA protocol information on Windows during request
shutdown.
@EdmondDantes
Copy link
Copy Markdown
Author

Hi please target PHP-8.5 (without the last .0) thanks :)

Done

@devnexen
Copy link
Copy Markdown
Member

How difficult would be to make test/reproducer ?

@EdmondDantes
Copy link
Copy Markdown
Author

How difficult would be to make test/reproducer ?

Hello. Sorry I didn’t see the message earlier. I need to think about how to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants